/*
 * PacketFileSource.h
 *
 *  Created on: 2016年10月9日
 *      Author: zhengboyuan
 */

#ifndef PACKETFILESOURCE_H_
#define PACKETFILESOURCE_H_

#include <MediaSource.h>
#include "PacketFile.h"
#include <fstream>


namespace av
{

class PacketFileSource: public MediaSource
{
public:
	static const char*	FILE_EXT;

public:
	PacketFileSource();
	virtual ~PacketFileSource();

	virtual int open(const std::string& url, const std::string& params);

	virtual void close();

	virtual bool isOpen();

	virtual bool getFormat(MediaFormat& fmt);

    virtual int getDuration();

	virtual int play();
	virtual int pause();
	virtual void stop();

	virtual int getState();

	virtual bool seekable();

	virtual int seek(int64_t offset);

	virtual int64_t getTime();

	virtual int setScale(float scale);

	virtual float getScale();

	virtual int read(AVPacket& pkt);

    virtual void interrupt();

    virtual bool isLive();

	virtual bool getMetaData(const std::string& key, std::string& value);

protected:
	bool readFormat();

protected:
	std::string	m_url;
	std::string m_params;

	PacketIndexFile	m_indexFile;

	std::ifstream	m_ifs;
	int64_t	m_curTime;
	MediaFormat	m_format;

};


} /* namespace av */

#endif /* PACKETFILESOURCE_H_ */
